import request from '@/utils/request'

export function getList(params) {
  return request({
    url: '/vue-admin-template/books/list',
    method: 'get',
    params
  }).then(res => res.data)
}

export function getInfo(params) {
  return request({
    url: '/vue-admin-template/books/info',
    method: 'get',
    params
  }).then(res => res.data)
}

export function saveBook(params) {
  return request({
    url: '/vue-admin-template/books/save',
    method: 'post',
    params
  }).then(res => res.data)
}

export function deleteBook(params) {
  return request({
    url: '/vue-admin-template/books/delete',
    method: 'post',
    params
  }).then(res => res.data)
}

export function getType(params) {
  return request({
    url: '/vue-admin-template/books/type',
    method: 'get',
    params
  }).then(res => {
    const {
      data
    } = res
    return data.map(v => ({
      label: v.name,
      value: v.id
    }))
  })
}

export function getCategory(params) {
  return request({
    url: '/vue-admin-template/books/category',
    method: 'get',
    params
  }).then(res => {
    const { data } = res
    return data.map(v => ({
      label: v.name,
      value: v.id
    }))
  })
}

export function returnBook(params) {
  return request({
    url: '/vue-admin-template/books/return',
    method: 'get',
    params
  }).then(res => res.data)
}
